]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-wm: Remove takeover_keybinding()
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 7 Nov 2011 01:16:15 +0000 (02:16 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 21 Nov 2011 23:42:28 +0000 (00:42 +0100)
Introspection support is now good enough to set a custom keybinding
handler directly from JS.

https://bugzilla.gnome.org/show_bug.cgi?id=663584

js/ui/main.js
js/ui/windowManager.js
src/shell-wm.c
src/shell-wm.h

index 6849292e0ee0eea81c03fc41c076f66039131b4b..c160fee0d72683a2fd366f8ca0a144ab4a0676f3 100644 (file)
@@ -132,15 +132,11 @@ function _initUserSession() {
     ExtensionSystem.init();
     ExtensionSystem.loadExtensions();
 
-    let shellwm = global.window_manager;
-
-    shellwm.takeover_keybinding('panel-run-dialog');
-    shellwm.connect('keybinding::panel-run-dialog', function () {
+    Meta.keybindings_set_custom_handler('panel-run-dialog', function() {
        getRunDialog().open();
     });
 
-    shellwm.takeover_keybinding('panel-main-menu');
-    shellwm.connect('keybinding::panel-main-menu', function () {
+    Meta.keybindings_set_custom_handler('panel-main-menu', function () {
         overview.toggle();
     });
 
index b9b4181df93eccd84fcea72afb395d2328f6fefa..4343a2012a70db8be033577f885a598a11aa1e5b 100644 (file)
@@ -92,7 +92,6 @@ WindowManager.prototype = {
     _init : function() {
         this._shellwm =  global.window_manager;
 
-        this._keyBindingHandlers = [];
         this._minimizing = [];
         this._maximizing = [];
         this._unmaximizing = [];
@@ -121,15 +120,24 @@ WindowManager.prototype = {
         this._shellwm.connect('destroy', Lang.bind(this, this._destroyWindow));
 
         this._workspaceSwitcherPopup = null;
-        this.setKeybindingHandler('switch-to-workspace-left', Lang.bind(this, this._showWorkspaceSwitcher));
-        this.setKeybindingHandler('switch-to-workspace-right', Lang.bind(this, this._showWorkspaceSwitcher));
-        this.setKeybindingHandler('switch-to-workspace-up', Lang.bind(this, this._showWorkspaceSwitcher));
-        this.setKeybindingHandler('switch-to-workspace-down', Lang.bind(this, this._showWorkspaceSwitcher));
-        this.setKeybindingHandler('switch-windows', Lang.bind(this, this._startAppSwitcher));
-        this.setKeybindingHandler('switch-group', Lang.bind(this, this._startAppSwitcher));
-        this.setKeybindingHandler('switch-windows-backward', Lang.bind(this, this._startAppSwitcher));
-        this.setKeybindingHandler('switch-group-backward', Lang.bind(this, this._startAppSwitcher));
-        this.setKeybindingHandler('switch-panels', Lang.bind(this, this._startA11ySwitcher));
+        Meta.keybindings_set_custom_handler('switch-to-workspace-left',
+                                            Lang.bind(this, this._showWorkspaceSwitcher));
+        Meta.keybindings_set_custom_handler('switch-to-workspace-right',
+                                            Lang.bind(this, this._showWorkspaceSwitcher));
+        Meta.keybindings_set_custom_handler('switch-to-workspace-up',
+                                            Lang.bind(this, this._showWorkspaceSwitcher));
+        Meta.keybindings_set_custom_handler('switch-to-workspace-down',
+                                            Lang.bind(this, this._showWorkspaceSwitcher));
+        Meta.keybindings_set_custom_handler('switch-windows',
+                                            Lang.bind(this, this._startAppSwitcher));
+        Meta.keybindings_set_custom_handler('switch-group',
+                                            Lang.bind(this, this._startAppSwitcher));
+        Meta.keybindings_set_custom_handler('switch-windows-backward',
+                                            Lang.bind(this, this._startAppSwitcher));
+        Meta.keybindings_set_custom_handler('switch-group-backward',
+                                            Lang.bind(this, this._startAppSwitcher));
+        Meta.keybindings_set_custom_handler('switch-panels',
+                                            Lang.bind(this, this._startA11ySwitcher));
 
         Main.overview.connect('showing', Lang.bind(this, function() {
             for (let i = 0; i < this._dimmedWindows.length; i++)
@@ -141,16 +149,6 @@ WindowManager.prototype = {
         }));
     },
 
-    setKeybindingHandler: function(keybinding, handler){
-        if (this._keyBindingHandlers[keybinding])
-            this._shellwm.disconnect(this._keyBindingHandlers[keybinding]);
-        else
-            this._shellwm.takeover_keybinding(keybinding);
-
-        this._keyBindingHandlers[keybinding] =
-            this._shellwm.connect('keybinding::' + keybinding, handler);
-    },
-
     blockAnimations: function() {
         this._animationBlockCount++;
     },
@@ -534,37 +532,41 @@ WindowManager.prototype = {
         shellwm.completed_switch_workspace();
     },
 
-    _startAppSwitcher : function(shellwm, binding, mask, window, backwards) {
+    _startAppSwitcher : function(display, screen, window, binding) {
         /* prevent a corner case where both popups show up at once */
         if (this._workspaceSwitcherPopup != null)
             this._workspaceSwitcherPopup.actor.hide();
 
         let tabPopup = new AltTab.AltTabPopup();
 
-        if (!tabPopup.show(backwards, binding, mask))
+        let modifiers = binding.get_modifiers();
+        let backwards = modifiers & Meta.VirtualModifier.SHIFT_MASK;
+        if (!tabPopup.show(backwards, binding.get_name(), binding.get_mask()))
             tabPopup.destroy();
     },
 
-    _startA11ySwitcher : function(shellwm, binding, mask, window, backwards) {
-        Main.ctrlAltTabManager.popup(backwards, mask);
+    _startA11ySwitcher : function(display, screen, window, binding) {
+        let modifiers = binding.get_modifiers();
+        let backwards = modifiers & Meta.VirtualModifier.SHIFT_MASK;
+        Main.ctrlAltTabManager.popup(backwards, binding.get_mask());
     },
 
-    _showWorkspaceSwitcher : function(shellwm, binding, mask, window, backwards) {
-        if (global.screen.n_workspaces == 1)
+    _showWorkspaceSwitcher : function(display, screen, window, binding) {
+        if (screen.n_workspaces == 1)
             return;
 
         if (this._workspaceSwitcherPopup == null)
             this._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup();
 
-        if (binding == 'switch-to-workspace-up')
+        if (binding.get_name() == 'switch-to-workspace-up')
             this.actionMoveWorkspaceUp();
-        else if (binding == 'switch-to-workspace-down')
+        else if (binding.get_name() == 'switch-to-workspace-down')
             this.actionMoveWorkspaceDown();
         // left/right would effectively act as synonyms for up/down if we enabled them;
         // but that could be considered confusing.
-        // else if (binding == 'switch-to-workspace-left')
+        // else if (binding.get_name() == 'switch-to-workspace-left')
         //   this.actionMoveWorkspaceLeft();
-        // else if (binding == 'switch-to-workspace-right')
+        // else if (binding.get_name() == 'switch-to-workspace-right')
         //   this.actionMoveWorkspaceRight();
     },
 
index dbc47aba38e6badbf8ddfbd3c93a9c3b9ec5b4ab..bfa9728828cd660944661bdc27dd7721e3151d80 100644 (file)
@@ -28,8 +28,6 @@ enum
   KILL_SWITCH_WORKSPACE,
   KILL_WINDOW_EFFECTS,
 
-  KEYBINDING,
-
   LAST_SIGNAL
 };
 
@@ -126,34 +124,6 @@ shell_wm_class_init (ShellWMClass *klass)
                  g_cclosure_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  META_TYPE_WINDOW_ACTOR);
-
-  /**
-   * ShellWM::keybinding:
-   * @shellwm: the #ShellWM
-   * @binding: the keybinding name
-   * @mask: the modifier mask used
-   * @window: for window keybindings, the #MetaWindow
-   * @backwards: for "reversible" keybindings, whether or not
-   * the backwards (Shifted) variant was invoked
-   *
-   * Emitted when a keybinding captured via
-   * shell_wm_takeover_keybinding() is invoked. The keybinding name
-   * (which has underscores, not hyphens) is also included as the
-   * detail of the signal name, so you can connect just specific
-   * keybindings.
-   */
-  shell_wm_signals[KEYBINDING] =
-    g_signal_new ("keybinding",
-                 G_TYPE_FROM_CLASS (klass),
-                 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
-                 0,
-                 NULL, NULL,
-                 _shell_marshal_VOID__STRING_UINT_OBJECT_BOOLEAN,
-                 G_TYPE_NONE, 4,
-                  G_TYPE_STRING,
-                  G_TYPE_UINT,
-                  META_TYPE_WINDOW,
-                  G_TYPE_BOOLEAN);
 }
 
 void
@@ -324,37 +294,3 @@ shell_wm_new (MetaPlugin *plugin)
 
   return wm;
 }
-
-static void
-shell_wm_key_handler (MetaDisplay    *display,
-                      MetaScreen     *screen,
-                      MetaWindow     *window,
-                      XEvent         *event,
-                      MetaKeyBinding *binding,
-                      gpointer        data)
-{
-  ShellWM *wm = data;
-  gboolean backwards = (event->xkey.state & ShiftMask);
-
-  g_signal_emit (wm, shell_wm_signals[KEYBINDING],
-                 g_quark_from_string (binding->name),
-                 binding->name, binding->mask, window, backwards);
-}
-
-/**
- * shell_wm_takeover_keybinding:
- * @wm: the #ShellWM
- * @binding_name: a meta keybinding name
- *
- * Tells mutter to forward keypresses for @binding_name to the shell
- * rather than processing them internally. This will cause a
- * #ShellWM::keybinding signal to be emitted when that key is pressed.
- */
-void
-shell_wm_takeover_keybinding (ShellWM      *wm,
-                              const char   *binding_name)
-{
-  meta_keybindings_set_custom_handler (binding_name,
-                                       shell_wm_key_handler,
-                                       wm, NULL);
-}
index 81fe83f13425ab96c4bc4ea7ab1cd42b429c7bbe..20b740a3b9c395ad20a6561d85f57d14cb2287fe 100644 (file)
@@ -39,10 +39,6 @@ void     shell_wm_completed_destroy          (ShellWM         *wm,
                                               MetaWindowActor *actor);
 void     shell_wm_completed_switch_workspace (ShellWM         *wm);
 
-/* Keybinding stuff */
-void shell_wm_takeover_keybinding (ShellWM    *wm,
-                                  const char *binding_name);
-
 G_END_DECLS
 
 #endif /* __SHELL_WM_H__ */